<template>
  <div>
    <my-head :title="$route.name"></my-head>
    <div class="wrap">
      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
        <van-swipe-item v-for="banner in pics" :key="banner.id">
          <img :src="banner.pic">
        </van-swipe-item>
      </van-swipe>
      <span class="shopName">{{ basicInfo.name }}</span>
      <div class="content" v-html="content"></div>
    </div>
    <!-- 弹出商品规格 -->
    <van-popup
     v-model="showSku"
     position="bottom"
     :style="{ height: '30%' }"
     round
     closeable
     >
       <van-card
          :num="sku.number"
          :price="sku.minPrice"
          :title="sku.name"
          :thumb="sku.pic"
         >
          <template #footer>
            <van-stepper v-model="sku.number" />
          </template>
         </van-card>
         <van-button color="#ff734c" size="large" round>块级元素</van-button>
     </van-popup>
    <!-- /弹出商品规格 -->
    <!-- 商品行动栏 -->
    <van-goods-action>
      <van-goods-action-icon icon="wap-home-o" text="首页" @click="$router.push('/home')" />
      <van-goods-action-icon icon="cart-o" text="购物车"  />
      <van-goods-action-button
        type="danger"
        text="立即购买"
        @click="showPopup"
      />
    </van-goods-action>
    <!-- /商品行动栏 -->
  </div>
</template>

<script>
import MyHead from '../../components/MyHead'
import { fetchDetail } from '../../api'
export default {
  data: () => {
    return {
      basicInfo: {},
      content: '',
      pics: [],
      showSku: false,
      // 商品规格
      sku: {}
    }
  },
  created () {
    this.fetchDetail()
  },
  methods: {
    fetchDetail () {
      fetchDetail(this.$route.params.id).then(res => {
        console.log(res)
        if (res.data.code === 0) {
          this.basicInfo = res.data.data.basicInfo
          this.content = res.data.data.content.replace(/<img/gi, '<img style="display:block;width:100%"')
          this.pics = res.data.data.pics
          this.sku = {
            ...res.data.data.basicInfo,
            number: 1
          }
        }
      })
    },
    showPopup () {
      this.showSku = true
    }
  },
  components: {
    MyHead
  }

}
</script>

<style lang="scss" scoped>
.wrap{
  padding-top: 46px;
  .my-swipe{
    width: 10rem;
    height: 5rem;
    img{
      width: 100%;
      height: 100%;
    }
  }
  .shopName{
    display: block;
    margin: 10px 20px;
    font-size: 16px;
    color:#333;
  }
}
</style>
